package com.example.droideep.fragment.animstudy.animator;

import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.animation.AccelerateInterpolator;

/**
 * Created by goodev on 15/5/16.
 */
public class SlideFromBottomAnimator {

    private float end = 0, start = 0;
    private int duration = 3300;
    private TimeInterpolator interpolator = new AccelerateInterpolator();

    //===================================
    public SlideFromBottomAnimator(Activity act, int duration) {
        if (android.os.Build.VERSION.SDK_INT >= 13) {
            Point p = new Point();
            act.getWindowManager().getDefaultDisplay().getSize(p);
            start = p.y;
        } else {
            DisplayMetrics d = new DisplayMetrics();
            act.getWindowManager().getDefaultDisplay().getMetrics(d);
            start = d.widthPixels;
        }
        this.duration = duration;
    }

    //===================================
    public void setInterpolator(TimeInterpolator ip) {
        interpolator = ip;
    }

    //===================================
    public ValueAnimator getAnimator(View v) {
        ValueAnimator anim = ObjectAnimator.ofFloat(v, "translationY", start, end);
        anim.setInterpolator(interpolator);
        anim.setDuration(duration);
        return anim;
    }

    //===================================
    public void start(View v) {
        ValueAnimator anim = getAnimator(v);
        anim.start();
    }
}
